package com.rao.config.websecurity.core;

import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityContextUtil {

    /**
     * @return 返回当前用户的id
     */
    public static Long getUserId() {
        SecurityContext context = SecurityContextHolder.getContext();
        SysUserDetails userDetails = (SysUserDetails) context.getAuthentication().getPrincipal();
        return userDetails.getUserId();
    }
}
